package com.easyidea.its.web.action.operationrecord;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.easyidea.its.domain.model.system.OperationRecord;
import com.easyidea.its.facade.operationrecord.OperationRecordMgr;
import com.easyidea.its.util.DateUtil;
import com.easyidea.its.util.PageUtil;
import com.easyidea.its.util.Result;
import com.easyidea.its.web.action.base.ItsBaseAction;

public class OperationRecordAction extends ItsBaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3438538898349522110L;
	
	private OperationRecordMgr operationRecordMgr;
	
	private String startDate;
	
	private String endDate;
	
	private Result<OperationRecord> result;
	

	public Result<OperationRecord> getResult() {
		return result;
	}

	public void setResult(Result<OperationRecord> result) {
		this.result = result;
	}

	public OperationRecordMgr getOperationRecordMgr() {
		return operationRecordMgr;
	}

	public void setOperationRecordMgr(OperationRecordMgr operationRecordMgr) {
		this.operationRecordMgr = operationRecordMgr;
	}
	@SuppressWarnings("unchecked")
	public String operationRecordList() {
		if(startDate == null) {
			startDate = DateUtil.dateToShortStr(DateUtil.getDateBerforByWeek(new Date(), 1));
		}
		if (endDate == null) {
			endDate =  DateUtil.dateToShortStr(new Date());
			
		}
		int totalRecords = operationRecordMgr.getOperationRecordsCount(DateUtil.strToDate(startDate),  DateUtil.strToDate(endDate));
		if (totalRecords > 0) {
			List<OperationRecord> records = operationRecordMgr.getOperationRecords(DateUtil.strToDate(startDate),  DateUtil.strToDate(endDate),(currentPage - 1) * pageSize,
					pageSize);
			result = PageUtil.createResult(pageSize, currentPage, totalRecords, records);
		} else {
			result = PageUtil.createResult(pageSize, currentPage, 0, new ArrayList());
		}
		return SUCCESS;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}




}
